﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PQ.IBL;
using System.IO;
using PQ.Model;

namespace PQ
{
    /// <summary>
    /// 验证码
    /// </summary>
    public partial class FrmVerifyCode : Form
    {
        private IBLUser blUser;
        private UserEntity userEntity;

        public FrmVerifyCode(IBLUser blUser, UserEntity userEntity)
        {
            InitializeComponent();
            this.blUser = blUser;
            this.userEntity = userEntity;
        }

        private void VerifyCodeForm_Load(object sender, EventArgs e)
        {
            LoadImage();
        }

        private void txtVerify_KeyUp(object sender, KeyEventArgs e)
        {
            if (this.txtVerify.Text.Length >= 5 || e.KeyData == Keys.Enter)
            {
                if (this.txtVerify.Text.Trim().Length<=2)
                {
                    LoadImage();
                }
                else
                {
                    userEntity.VerifyCode = this.txtVerify.Text;
                    this.Close();
                }
            }
        }

        private void LoadImage()
        {
            Stream stream = blUser.GetVerifyCodePicStream(userEntity);
            if (stream != null)
            {
                pictureBox1.Image = Image.FromStream(stream);
            }
        }
    }
}
